import Vue from 'vue'
import Router from 'vue-router'
import home from '@/components/home'
import test from '@/components/test'

Vue.use(Router);

let router=new Router({
  mode: 'hash',
  routes: [
    {
      path: '',
      redirect: {
        name: 'home',
      }
    },
    {
      path: '/home',
      name: 'home',
      component: home,
    },
    {
      path: '/test',
      name: 'test',
      component: test,
    },
  ]
})
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    router.replace(targetPath);
  }
});

export default router
